package
{
	import flash.display.Sprite;
	import flash.geom.Point;

	public class Tile
	{
		private var m_color:uint;
		public var display:Sprite;
		private var m_tileSize:Number;
		
		public var x:int;
		public var y:int;
		private var m_interactable:Boolean;
		
		public function Tile(tileSize:Number)
		{
			m_tileSize = tileSize;
			display = new Sprite();
			display.graphics.drawRect(0,0,tileSize,tileSize);
			interactable = false;
		}
		
		public function getStringXY():String
		{
			return String(x) + ',' + String(y);
		}
		
		public function get tileSize():Number
		{
			return m_tileSize;
		}
		
		public function set interactable(val:Boolean):void
		{
			m_interactable = val;
			display.alpha = (val) ? 1 : .5;
		}
		
		public function get interactable():Boolean
		{
			return m_interactable;
		}
		
		public function setPosition(x:int, y:int):void
		{
			this.x = x;
			this.y = y;
		}
		
		public function getColor():uint
		{
			return m_color;
		}
		
		public function setColor(color:uint):void
		{
			m_color = color;
			display.graphics.clear();
			display.graphics.lineStyle(1);
			display.graphics.beginFill(color);
			display.graphics.drawRect(0,0,m_tileSize, m_tileSize);
			display.graphics.endFill();
		}
		
		
		public static function createNewTile(x:int, y:int, tileSize:Number, colors:Array):Tile
		{
			var tile:Tile = new Tile(tileSize);
			tile.setColor(Util.getRandomElementFromArray(colors));
			tile.setPosition(x, y);
			return tile;			
		}
		
	}
}